<template>
<div class="modal fade " :class="{'modal_show':againlogin && $route.path!='/login'}" >
      <div class="modal-dialog modal_login" >
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title">登录</h4>
          </div>
          <div class="modal-body">
              <input type="text" v-model="user.username">
              <input type="password" v-model="user.password">
          </div>
          <div class="modal-footer textcenter">
              
              <button  v-on:click="login" >重新登录</button>
          </div>
        </div>
      </div>
    </div>
</template>
<script>
export default {
    data(){
        return {
            user:{
                username:'chuanshi',clientType:'O',password:'cs2017br'
            }
        }
    },
    methods:{
        login(){
            var that=this;
            this.$ajax.post('/token/getPublicKey',{a:2}).then(function(res){
                res=res.data;
                if(res.errorCode==0){
                    var k=res.data;
                    var encrypt = new JSEncrypt();
                    encrypt.setPublicKey(k);
                    var user=JSON.parse(JSON.stringify(this.user));
                    this.user.password='';
                    user.password=encrypt.encrypt(user.password);
                    this.$ajax.post('/token/get',user).then(function(res){
                        res=res.data;
                        if(res && res.errorCode==0){
                            that.$store.commit('SET_ONLINE_USER',res.data);
					        that.storage.setItem('user',JSON.stringify(res.data));
                            that.$store.commit('SETAGAINLOGIN',false);
                        }else{
                            alert(res.message);
                        }
                    })
                }
            }.bind(this))
            
        }
    },computed:{
        againlogin:{
            get(){
                return this.$store.state.options.againlogin
            },
            set (val){
                this.$sotre.commit('SETAGAINLOGIN',val);
            }
        }
    }
}
</script>